package com.wc.AlgoOJ_train.train3_算法大礼包.c4_二分枚举.AG0112_电话线;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/16 10:38
 * @description http://43.138.190.70:8888/p/AG0112
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010, M = 20010, INF = 0x3f3f3f3f;
    static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M];
    // f[i][j] 表示 到达 i 免费了 j 次花的最少的钱
    static int[][] f = new int[N][N];
    static boolean[][] st = new boolean[N][N];
    static PriorityQueue<int[]> q = new PriorityQueue<>(Comparator.comparingInt(o -> o[0]));
    static int n, m, k, idx = 1;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
            add(a, b, c);
            add(b, a, c);
        }
        dijkstra();
        int res = INF;
        for (int i = 0; i <= k; i++) res = Math.min(res, f[n][i]);
        out.println(res == INF ? -1 : res);
        out.flush();
    }

    static void dijkstra() {
        for (int i = 1; i <= n; i++) Arrays.fill(f[i], INF);
        // dist, t, use
        q.add(new int[]{0, 1, 0});
        f[1][0] = 0;
        while (!q.isEmpty()) {
            int[] t = q.poll();
            int d = t[0], u = t[1], use = t[2];
            if (st[u][use]) continue;
            st[u][use] = true;
            for (int i = h[u]; i > 0; i = ne[i]) {
                int j = e[i];
                // 不使用
                if (!st[j][use] && Math.max(d, w[i]) < f[j][use]) {
                    f[j][use] = Math.max(d, w[i]);
                    q.add(new int[]{f[j][use], j, use});
                }
                // 使用
                if (use < k && !st[j][use + 1] && d < f[j][use + 1]) {
                    f[j][use + 1] = d;
                    q.add(new int[]{f[j][use + 1], j, use + 1});
                }
            }
        }
    }

    static void add(int a, int b, int c) {
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
